﻿using B.S.DataBase.MyProject.ErrorCode;
using B.S.Traceability.Domain;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Applicantion.Command.SupplierCommand;
using MediatR;

namespace B.S.Traceability.Read.API.Applicantion.CommandHandler.SupplierCommandHandler
{
    public class QuerySupplierCommandHandler : IRequestHandler<QuerySupplierCommand, APIResult<List<SU_Supplier>>>
    {
        private readonly IBaseRepository<SU_Supplier> suppRep;
        public QuerySupplierCommandHandler(IBaseRepository<SU_Supplier> suppRep)
        {
            this.suppRep = suppRep;
        }

        public Task<APIResult<List<SU_Supplier>>> Handle(QuerySupplierCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SU_Supplier>> result = new APIResult<List<SU_Supplier>>();
            var lsit = suppRep.GetAll().Result.Where(x => x.ProductionCode == request.ProductionCode&&x.SupType==request.SupType);
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = lsit.ToList();
            return Task.FromResult(result);
        }
    }
}
